<template>
	<view class="goods-item" v-if="!row">
		<view class="goods-item-left">
			<radio :checked="goods.goodsState" @click="radioClickHandler" color="#52e3fc" v-if="showRadio"/>
			<image :src="$imageUrl + goods.goodsImg"></image>
		</view>
		<view class="goods-item-right">
			<view class="goods-name">
				{{goods.goodsName}}
			</view>
			<view class="goods-info-box">
				<view class="goods-desc">
					{{ goods.goodsOptions || goods.storeName }}
				</view>
				<view class="price-box">		
					<view class="goods-price">
						￥<text>{{goods.goodsPrice | tofixed}}</text>
					</view>
					<uni-number-box :min="1" :value="goods.goodsCount"  background="#2979FF" color="#fff" v-if="showNum" @change="numChangeHandler"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
	<view class="production-item" v-else>
		<view class="production-image">
			<image :src="$imageUrl + goods.goodsImg"></image>
		</view>
		<view class="production-desc">
			{{ goods.goodsName }}
		</view>
		<view class="production-price">
			￥<span>{{ goods.goodsPrice }}</span>
		</view>
	</view>
</template>

<script>
	export default {
		name:"my-goods",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNum: {
				type: Boolean,
				default: false
			},
			row: {
				type: Boolean,
				default: false
			}
		},
		filters: {
			tofixed(num) {
				return Number(num).toFixed(2)
			}
		},
		data() {
			return {
				
			}
		},
		methods: {
			radioClickHandler() {
				console.log(this.goods);
				this.$emit("change-radio", {
					goodsId: this.goods.goodsId,
					goodsState: !this.goods.goodsState,
					createTime: this.goods.createTime
				})
			},
			numChangeHandler(val) {
				this.$emit("num-change", {
					goodsId: this.goods.goodsId,
					goodsCount: + val,
					createTime: this.goods.createTime
				})
			}
		}
	}
</script>

<style lang="scss">
.goods-item {
	display: flex;
	padding: 20rpx;
	background-color: #fff;
	border-bottom: 1px solid #f5f5f5;
}
.goods-item-left {
	display: flex;
	align-items: center;
	image {
		width: 188rpx;
		height: 188rpx;
		border: 1px solid #f5f5f5;
	}
	radio {
		text-align: center;
		margin-right: 10rpx;
	}
}
.goods-item-right {
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	margin-left: 20rpx;
	.goods-name {
		font-size: 12px;
		overflow: hidden; //多出的隐藏
		//text-overflow: ellipsis;//多出部分用...代替
		display: -webkit-box; //定义为盒子模型显示
		-webkit-line-clamp: 2; //用来限制在一个块元素显示的文本的行数
		-webkit-box-orient: vertical; //从上到下垂直排列子元素（设置伸缩盒子的子元素排列方式）
		margin-bottom: 10rpx;
	}
}
.goods-info-box {
	.goods-desc {
		color: #d9d9d9;
		font-size: 12px;
		overflow: hidden; //多出的隐藏
		//text-overflow: ellipsis;//多出部分用...代替
		display: -webkit-box; //定义为盒子模型显示
		-webkit-line-clamp: 2; //用来限制在一个块元素显示的文本的行数
		-webkit-box-orient: vertical; //从上到下垂直排列子元素（设置伸缩盒子的子元素排列方式）
		margin-bottom: 10rpx;
	}
	.price-box {
		display: flex;
		justify-content: space-between
	}
	.goods-price {
		color: #000;
		display: flex;
		align-items: flex-end;
		font-size: 12px;
		font-weight: bold;
		text {
			font-size: 16px;
		}
	}
}
/deep/ .uni-numbox__plus,
/deep/ .uni-numbox-btns {
	width: 30px;
	height: 30px;
}

.production-item {
	width: 100%;
	padding: 20rpx;
	box-sizing: border-box;
	background-color: #fff;
	border: 1rpx #eee solid;
	border-bottom: none;
	border-right: none;
	.production-image {
		width: 100%;
		height: 300rpx;
		image {
			width: 100%;
			height: 300rpx;
			display: block;
		}
	}
	.production-desc {
		font-size: 14px;
		margin-top: 20rpx;
		overflow: hidden; //多出的隐藏
		//text-overflow: ellipsis;//多出部分用...代替
		display: -webkit-box; //定义为盒子模型显示
		-webkit-line-clamp: 2; //用来限制在一个块元素显示的文本的行数
		-webkit-box-orient: vertical; //从上到下垂直排列子元素（设置伸缩盒子的子元素排列方式）
	}
	.production-price {
		margin-top: 16rpx;
		font-size: 14px;
		font-weight: bold;
		span {
			font-size: 18px;
		}
	}
}
</style>